<?php
namespace Admin\Controller;
class CommentController extends CommonController
{
    private $obj;

    public function _initialize()
    {
        parent::_initialize();
        $this->obj = M('comment');
    }

    public function index()
    {
      $condition = $this->_search();
        $count = $this->obj->where($condition)->count();
        $page = I('get.p', 1, 'int');
        $pagesize = 20;
        $pageObj = new \Org\Util\Page($count, $pagesize);
        $lists = $this->obj->where($condition)->order('id desc')->page($page, $pageObj->listRows)->select();
        $this->lists = $lists;
        $this->pages = $pageObj->show();
        $this->assign('list_table', true);
        $this->display();
    }
    protected function _search() {
        $map = array();
        ($keyword = I('get.keyword')) && $map['house_title'] = array('like', '%'.$keyword.'%');

        if( $_GET['status']==null ){
            $status = -1;
        }else{
            $status = intval($_GET['status']);
        }
        $status>=0 && $map['status'] = array('eq',$status);

        $this->assign('search', array(

            'status'  => $status,
            'keyword' => $keyword

        ));
        return $map;
    }
    protected function _before_update($data){
        $data['rename'] =  $_SESSION['username'];
        $data['re_time'] = time();
        return $data;
    }
}